<?php
/**
 * Created by PhpStorm.
 * User: shkj
 * Date: 2020/4/23
 * Time: 14:27
 */

namespace app\api\model;


use think\Model;

class Attr extends Model
{
    protected $hidden = ['id','attr_type','type_id','attr_values'];

    public function select($id='',$type=''){
     $res = db('attr')->field('id,attr_values,attr_name')->where('type_id',$id)->where('attr_type',$type)->select();
     if($res){
     	return_json(200,'成功',$res);
     }else{
     	return_json(400,'失败',false);
     }
    }

    public function add($data){
    	
    	$res = self::save($data);
    	if($res){
    		return_json(200,'成功',true);
     }else{
     	return_json(400,'失败',false);
     }
    }

    public function detail($id){
        $res = db('attr')->field('id,attr_name')->where('id',$id)->find();
        if($res){
     	return_json(200,'成功',$res);
     }else{
     	return_json(400,'失败',false);
     }

    }

    public function edit($id,$data){
    	$res = self::where('id',$id)->update($data);
    	if($res){
    		return_json(200,'成功',true);
     }else{
     	return_json(400,'失败',false);
     }
    }

    public function del($id){
       $res = db('attr')->delete($id);
    	if($res){
    		return_json(200,'成功',true);
     }else{
     	return_json(400,'失败',false);
     }
    }

    public function insert($id,$type_id,$data){
    	$res = self::where('id',$id)->where('type_id',$type_id)->update($data);
    	if($res){
    		return_json(200,'成功',true);
     }else{
     	return_json(400,'失败',false);
     }

    }

}